import os


def show():
    global sta
    os.system('cls' if os.name == 'nt' else 'clear')
    for i in range(3):
        for j in range(3):
            print(sta[i * 3 + j], end='\t| ')
        print()


def judge():
    global detail
    global sta
    a = True
    detail = ''
    # 判定行
    for i in range(3):
        if sta[i * 3] == sta[i * 3 + 1] == sta[i * 3 + 2] != '':
            a = False
            detail = sta[i * 3]
    # 判定列
    for i in range(3):
        if sta[i] == sta[i + 3] == sta[i + 6] != '':
            a = False
            detail = sta[i]
    # 判定对角线
    if sta[0] == sta[4] == sta[8] != '' or sta[2] == sta[4] == sta[6] != '':
        a = False
        detail = sta[4]
    if '' not in sta:
        a = False
    return a


detail = ''
sta = ['' for i in range(9)]
# sta = ['x', 'o', 'x', 'x', 'o', 'o', 'o', 'x', 'o']
player = 0
print('这是一个井字棋程序')
while judge():
    if os.name == 'nt':
        if player % 2 == 1:
            os.system('color a')
        elif player % 2 == 0:
            os.system('color c')
    print('本次是{}玩家'.format('o' if player % 2 == 0 else 'x'))
    try:
        x, y = map(int, input('请告诉我你要填入第几行第几列').split())
    except ValueError:
        print('你输入的不是用空格分隔的两个数字')
        continue
    if sta[(x - 1) * 3 + y - 1] != '':
        print('你选择的是已填充的')
    else:
        sta[(x - 1) * 3 + y - 1] = 'o' if player % 2 == 0 else 'x'
        player += 1
        show()
if '' not in sta:
    if os.name == 'nt':
        os.system('color d')
    print('该局平局')
else:
    if os.name == 'nt':
        os.system('color e')
    print('{}玩家胜利'.format(detail))
print('Game Over')
input()
